;
function getOption() {
    var programId = add_Obj.id;
    var parentId = add_Obj.pId;
    var opType = add_Obj.opType;
    var level = add_Obj.level;
    if(level == 1){
        $("#position_id").attr('disabled','true');
        $("#programForm input[name='url']").attr('disabled','true');
        $("#programForm input[name='status']").attr('disabled','true');
    }
    if (opType == 1) {
        $("#htmlTitle").html("新建栏目");
    } else if (opType == 2) {
        $("#htmlTitle").html("编辑栏目");
    }
    $(".save").click(function () {
        var options = {
            dataType: 'json',
            success: function (data) {
                if(add_Obj.page_type == 3) {
                    if (data.msg== 'success') {
                        var _p_obj = {
                            page_type: 3,//列表类型
                            pId: parentId,//上级ID
                            pId1: add_Obj.pId1
                        };
                        $.ajaxSetup({cache: false});
                        $(".mainDiv").load('htmlWeb/systemProgramaHtml', '', function () {
                            page_Obj = _p_obj;
                            $.getScript("../../by-webhtml/assets/js/system/system_programa.js");
                        });
                    } else {
                        if (data.r != null) alert("栏目编辑失败");
                        else alert("栏目新建失败");
                    }
                }else if(add_Obj.page_type == 2) {
                    if (data.msg== 'success') {
                        var _p_obj = {
                            page_type: 2,//列表类型
                            pId: parentId,//上级ID
                            pId1: add_Obj.pId1
                        };
                        $.ajaxSetup({cache: false});
                        $(".mainDiv").load('htmlWeb/systemProgramaHtml', '', function () {
                            page_Obj = _p_obj;
                            $.getScript("../../by-webhtml/assets/js/system/system_programa.js");
                        });
                    } else {
                        if (data.r != null) alert("栏目编辑失败");
                        else alert("栏目新建失败");
                    }
                }else if(add_Obj.page_type == 1) {
                    if (data.msg== 'success') {
                        var _p_obj = {
                            page_type: 1,//列表类型
                            pId: parentId,//上级ID
                            pId1: add_Obj.pId1
                        };
                        $.ajaxSetup({cache: false});
                        $(".mainDiv").load('htmlWeb/systemProgramaHtml', '', function () {
                            page_Obj = _p_obj;
                            $.getScript("../../by-webhtml/assets/js/system/system_programa.js");
                        });
                    } else {
                        if (data.r != null) alert("栏目编辑失败");
                        else alert("栏目新建失败");
                    }
                }
            }
        };
        $("#programForm").ajaxForm(options);
    });
    $("#cancel").click(function () {
        if(add_Obj.page_type == 3) {
            var _p_obj = {
                page_type: 3,//列表类型
                pId: parentId,//上级ID
                pId1: add_Obj.pId1
            };
            $(".mainDiv").load('htmlWeb/systemProgramaHtml', '', function () {
                page_Obj = _p_obj;
                $.getScript("../../by-webhtml/assets/js/system/system_programa.js");
            });
        }if(add_Obj.page_type == 2) {
            var _p_obj = {
                page_type: 2,//列表类型
                pId: parentId,//上级ID
                pId1: add_Obj.pId1
            };
            $(".mainDiv").load('htmlWeb/systemProgramaHtml', '', function () {
                page_Obj = _p_obj;
                $.getScript("../../by-webhtml/assets/js/system/system_programa.js");
            });
        }else {//广告栏目
            var _p_obj = {
                page_type: 1,//列表类型
                pId: parentId,//上级ID
                pId1: add_Obj.pId1
            };
            $(".mainDiv").load('htmlWeb/systemProgramaHtml', '', function () {
                page_Obj = _p_obj;
                $.getScript("../../by-webhtml/assets/js/system/system_programa.js");
            });
        }
    });
    $.post("htmlWeb/program/getOption", {id: programId}, function (data) {
        var _adOpt = "";
        $.each(data.adPosition, function (index, obj) {
            var opt = obj.split(";");
            _adOpt += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $("#position_id").append(_adOpt);
        if (programId != ''&& programId != undefined) {
            $("#programForm").setValues(data.channel);
           /* ue.addListener("ready", function () {
                ue.setContent(data.channel.descn);
            });*/
        }else {
            // console.log(parentId);
            $("#parentId").val(parentId);
            $("#programForm input[name='sort']").val(0);
        }
        $("#level").val(level);
    });
}
$(function () {
    getOption();
});
